﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PropertyAppraisal.DoemsKanCha
{
    public partial class DomePhoto : System.Web.UI.Page
    {
        private BLL.PhotoBll Pbll = new BLL.PhotoBll();
        protected void Page_Load(object sender, EventArgs e)
        {
            txtgong.Text = Request["id"];
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //判断上传文件不能为空
            if (FileUpload1.FileName == "")
            {
                this.Label1.Text = "上传图片不能为空";
                return;
            }
            //bool fileIsValid = false;
            ////判断上传的文件类型是否符合要求
            //if (this.FileUpload1.HasFile)
            //{
            //    string fileExtension = System.IO.Path.GetExtension(this.FileUpload1.FileName).ToLower();
            //    string[] restrictExtension = { ".gif", ".jpg", ".bmp", ".png" };
            //    //判断文件是否符合类型要求
            //    for (int i = 0; i < restrictExtension.Length; i++)
            //    {
            //        if (fileExtension == restrictExtension[i])
            //        {
            //            fileIsValid = true;
            //        }
            //        //如果文件符合类型，调用saveas方法实现上传，并显示相关信息
            //        if (fileIsValid == true)
            //        {
            //            //上传文件是否大于10m
            //            if (FileUpload1.PostedFile.ContentLength > (10 * 1024 * 1024))
            //            {
            //                this.Label1.Text = "上传文件过大";
            //                return;
            //            }
            //            try
            //            {
            var pronum = txtgong.Text;
            string imName1 = pronum + "厨房" + FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf('.'));
            this.Image1.ImageUrl = "~/images/" + imName1;
            this.FileUpload1.SaveAs(Server.MapPath("~/images/") + imName1);
            var url = this.Image1.ImageUrl;
            //添加
            Model.EAPhoto p = new Model.EAPhoto();
            p.projectNumber = pronum;
            p.photo_Name = imName1;
            p.photo_Url = url;
            p.photo_CreateTime = DateTime.Now;
            p.photo_CreatePeole = "小黑";
            var result = Pbll.Add(p);
            if (result)
            {
                this.Label1.Text = "上传成功";
            }
            else
            {
                this.Label1.Text = "上传失败";
            }
            //    }
            //    catch
            //    {
            //        this.Label1.Text = "上传失败";
            //    }
            //    finally
            //    {

            //    }
            //}
            //else
            //{
            //    this.Label1.Text = "图片格式不对";
            //}
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            //判断上传文件不能为空
            if (FileUpload2.FileName == "")
            {
                this.Label2.Text = "上传图片不能为空";
                return;
            }
            var pronum = txtgong.Text;
            string imName2 = pronum + "客厅" + FileUpload2.FileName.Substring(FileUpload2.FileName.LastIndexOf('.'));
            this.Image2.ImageUrl = "~/images/" + imName2;
            this.FileUpload2.SaveAs(Server.MapPath("~/images/") + imName2);
            var url = this.Image2.ImageUrl;
            //添加
            Model.EAPhoto p = new Model.EAPhoto();
            p.projectNumber = pronum;
            p.photo_Name = imName2;
            p.photo_Url = url;
            p.photo_CreateTime = DateTime.Now;
            p.photo_CreatePeole = "小黑";
            var result = Pbll.Add(p);
            if (result)
            {
                this.Label2.Text = "上传成功";
            }
            else
            {
                this.Label2.Text = "上传失败";
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            //判断上传文件不能为空
            if (FileUpload3.FileName == "")
            {
                this.Label3.Text = "上传图片不能为空";
                return;
            }
            var pronum = txtgong.Text;
            string imName3 = pronum + "居室" + FileUpload3.FileName.Substring(FileUpload3.FileName.LastIndexOf('.'));
            this.Image3.ImageUrl = "~/images/" + imName3;
            this.FileUpload3.SaveAs(Server.MapPath("~/images/") + imName3);
            var url = this.Image3.ImageUrl;
            //添加
            Model.EAPhoto p = new Model.EAPhoto();
            p.projectNumber = pronum;
            p.photo_Name = imName3;
            p.photo_Url = url;
            p.photo_CreateTime = DateTime.Now;
            p.photo_CreatePeole = "小黑";
            var result = Pbll.Add(p);
            if (result)
            {
                this.Label3.Text = "上传成功";
            }
            else
            {
                this.Label3.Text = "上传失败";
            }
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            //判断上传文件不能为空
            if (FileUpload4.FileName == "")
            {
                this.Label4.Text = "上传图片不能为空";
                return;
            }
            var pronum = txtgong.Text;
            string imName4 = pronum + "卧室" + FileUpload4.FileName.Substring(FileUpload4.FileName.LastIndexOf('.'));
            this.Image4.ImageUrl = "~/images/" + imName4;
            this.FileUpload4.SaveAs(Server.MapPath("~/images/") + imName4);
            var url = this.Image4.ImageUrl;
            //添加
            Model.EAPhoto p = new Model.EAPhoto();
            p.projectNumber = pronum;
            p.photo_Name = imName4;
            p.photo_Url = url;
            p.photo_CreateTime = DateTime.Now;
            p.photo_CreatePeole = "小黑";
            var result = Pbll.Add(p);
            if (result)
            {
                this.Label4.Text = "上传成功";
            }
            else
            {
                this.Label4.Text = "上传失败";
            }
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            //判断上传文件不能为空
            if (FileUpload5.FileName == "")
            {
                this.Label5.Text = "上传图片不能为空";
                return;
            }
            var pronum = txtgong.Text;
            string imName5 = pronum + "小区" + FileUpload5.FileName.Substring(FileUpload5.FileName.LastIndexOf('.'));
            this.Image5.ImageUrl = "~/images/" + imName5;
            this.FileUpload5.SaveAs(Server.MapPath("~/images/") + imName5);
            var url = this.Image5.ImageUrl;
            //添加
            Model.EAPhoto p = new Model.EAPhoto();
            p.projectNumber = pronum;
            p.photo_Name = imName5;
            p.photo_Url = url;
            p.photo_CreateTime = DateTime.Now;
            p.photo_CreatePeole = "小黑";
            var result = Pbll.Add(p);
            if (result)
            {
                this.Label5.Text = "上传成功";
            }
            else
            {
                this.Label5.Text = "上传失败";
            }
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            //判断上传文件不能为空
            if (FileUpload6.FileName == "")
            {
                this.Label6.Text = "上传图片不能为空";
                return;
            }
            var pronum = txtgong.Text;
            string imName6 = pronum + "广场" + FileUpload6.FileName.Substring(FileUpload6.FileName.LastIndexOf('.'));
            this.Image6.ImageUrl = "~/images/" + imName6;
            this.FileUpload6.SaveAs(Server.MapPath("~/images/") + imName6);
            var url = this.Image6.ImageUrl;
            //添加
            Model.EAPhoto p = new Model.EAPhoto();
            p.projectNumber = pronum;
            p.photo_Name = imName6;
            p.photo_Url = url;
            p.photo_CreateTime = DateTime.Now;
            p.photo_CreatePeole = "小黑";
            var result = Pbll.Add(p);
            if (result)
            {
                this.Label6.Text = "上传成功";
            }
            else
            {
                this.Label6.Text = "上传失败";
            }
        }
    }
}